package good.idea.data.excel.context;

import lombok.Data;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import good.idea.data.excel.call.DataLoadChannel;
import good.idea.data.excel.domain.PageData;
import good.idea.data.excel.domain.SheetDataChannel;
import good.idea.data.excel.listener.DataLoadListener;
import good.idea.data.excel.listener.RowWriteListener;

import java.util.*;

/**
 * @author chm
 */
@Data
public class ExcelWriteContext extends ExcelBaseContext {


    private Sheet activitySheet;

    private int activitySheetIndex;

    private SXSSFWorkbook outWorkbook;

    private int writeRowNum;

    private Set<String> sheetName = new LinkedHashSet<>();


    /**
     * 数据加载监听
     * 可以再监听中修改数据
     */
    private List<DataLoadListener> dataLoadListeners = new ArrayList<>();

    /**
     * 行数据写入监听
     */
    private List<RowWriteListener> rowWriteListeners = new ArrayList<>();

    /**
     * 数据加载通道
     */
    private DataLoadChannel loadChannel;

    /**
     * 数据加载通道
     */
    private List<DataLoadChannel> dataLoadChannels = new ArrayList<>();


    private Map<Integer, SheetDataChannel> sheetDataChannelMap = new HashMap<Integer, SheetDataChannel>();


    /**
     * 可写入的数据
     */
    private Object data = new HashMap<>();

    private PageData loadPageData = new PageData();

    public void addLoadListener(DataLoadListener loadListener) {
        dataLoadListeners.add(loadListener);
    }

    public void addWriteListener(RowWriteListener writeListener) {
        rowWriteListeners.add(writeListener);
    }


    public SheetDataChannel createSheetDataChannel(Integer index) {
        SheetDataChannel sheetDataChannel = new SheetDataChannel();
        sheetDataChannelMap.put(index, sheetDataChannel);
        return sheetDataChannel;
    }

    public SheetDataChannel createSheetDataChannel() {
        int size = sheetDataChannelMap.size();
        return createSheetDataChannel(size);
    }

    public void addDataLoadChannel(DataLoadChannel loadChannel) {
        dataLoadChannels.add(loadChannel);
    }


    public void addDataLoadChannel4(DataLoadChannel loadChannel) {
        dataLoadChannels.add(loadChannel);
    }


}
